import LXCOM from '../../../common/common.js'
import {LGXEnums}  from '../../../common/sysenum.js';

var LeftMoseDownTool = {

}

LeftMoseDownTool.action = function (dataManger, mosEvnt, worldPos) {
    dataManger.setDragFlag(false);
    var scaling = dataManger.getScaling();
    var mapscale = dataManger.getMapScale();
    var preSelGraph = dataManger.getCurentGraph();
    var pCurentGraph = dataManger.pickGraph(worldPos);
    if (pCurentGraph){
        dataManger.recordRepaintScope(pCurentGraph);
    }
    
    if (pCurentGraph != null) {
        dataManger.setCurentGraph(pCurentGraph);
    }
    else if (!mosEvnt.ctrlDown){
        if (preSelGraph) {
            var tMakePoint = new LXCOM.LGXPoint();
            tMakePoint.clone(worldPos);
            var selKind = preSelGraph.calculateSelKind(tMakePoint, scaling, mapscale, false);
            if (selKind > 0) {
                this.selGraphKind(preSelGraph, worldPos, scaling, mapscale, dataManger);
            }
            else {
                dataManger.setCurentGraph(null);
                dataManger.clearSelectList();
            }
        }
    }
    if (!mosEvnt.ctrlDown){
        this.chgGraphLight(preSelGraph, pCurentGraph);
    }
    if (pCurentGraph){
        dataManger.recordRepaintScope(pCurentGraph);
    }
}

LeftMoseDownTool.selGraphKind = function (pGraph, tPoint, scaling, mapscale, dataManger) {
    var tMakePoint = new LXCOM.LGXPoint();
    tMakePoint.clone(tPoint);
    let selKind = pGraph.calculateSelKind(tMakePoint, scaling, mapscale, false);
    if (selKind > 0) {
        pGraph.setSelect(pGraph.getSelect() + 1);
        pGraph.setSelKind(selKind);
    }
    else {
        pGraph.setSelect(0);
        pGraph.setSelKind(0);
    }
}

LeftMoseDownTool.chgGraphLight = function (preSelGraph, pCurentGraph) {
    if (pCurentGraph != null) {
        if (preSelGraph != null && pCurentGraph != preSelGraph) {
            preSelGraph.setSelect(0);
        }
    }
    else {
        if (preSelGraph != null) {
            preSelGraph.setSelect(0);
        }
    }
}
export default { LeftMoseDownTool }